package com.napier.unit3;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.Spanned;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class P3_textField extends Activity {
 
	EditText txt1, txt2_filtered;
	Button submit;
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        
        //Switch XML file
        setContentView(R.layout.textfield);
        
        txt1 = (EditText)findViewById(R.id.text_id_1);
        txt2_filtered = (EditText)findViewById(R.id.text_id_2);
        submit = (Button)findViewById(R.id.submit_id);
  
// <---------------- TO LOWER CASE FILTER  ------------------>
        InputFilter filter = new InputFilter() 
        {
           public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) 
           {
        	   String returnString = "";
        	   for (int i = start; i < end; i++) 
        	   {
        		  returnString += Character.toLowerCase(source.charAt(i));
        	   }
            return returnString;
           }
        };
        
        //Add the filter to the EditText
        txt2_filtered.setFilters(new InputFilter[]{filter});
        

        submit.setOnClickListener(new OnClickListener() 
		{
			public void onClick(View v) 
			{				
				Toast.makeText(P3_textField.this, "1 = "+txt1.getText()+ " 2 = " + txt2_filtered.getText(),Toast.LENGTH_SHORT).show();
			}    			
		}); 
    }
}